package mapReduce.demo05_shuffle.demo03_expressNumSort;

import org.apache.hadoop.io.Text;
import org.apache.hadoop.io.WritableComparable;
import org.apache.hadoop.io.WritableComparator;

public class ExpressNumSortComparator extends WritableComparator {

    public ExpressNumSortComparator() {
        super(Text.class,true);
    }

    @Override
    public int compare(WritableComparable a, WritableComparable b) {

        Text aBean = (Text) a;
        Text bBean = (Text) b;

        String aStr = aBean.toString();
        String bStr = bBean.toString();

        String aSecondField = aStr.split("-")[1];
        String bSecondField = bStr.split("-")[1];

        int aInt = Integer.parseInt(aSecondField);
        int bInt = Integer.parseInt(bSecondField);

        return aInt-bInt;

    }
}
